package com.bsoft.utils;

import org.apache.http.conn.HttpHostConnectException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * 创建日期 : 2019/9/10
 * 创建人 : 赵太行
 */
public class Base64Utils {
    /**
     * 字符串64加密
     * @param data
     * @return
     */
    private static String base64encodedString="";
    private static String base64decoderString="";
    public static String getBase64Encoder(String data) throws UnsupportedEncodingException,HttpHostConnectException

    {
        return Base64.getEncoder().encodeToString(data.getBytes("utf-8"));
//        return new BASE64Encoder().encode(data.getBytes());
    }
    /**
     * 解密
     */
    public static String getBase64Decoder(String data){

        //Base64 解密
        try {
//            byte[] decoded = Base64.getMimeDecoder().decode(data);
            byte[] decoded = new BASE64Decoder().decodeBuffer(data);
            base64decoderString = new String(decoded,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return base64decoderString;
    }
    public static void main(String args[]){
//        try {
//        String mm="56Wo5o2u5om55qyh5a+554Wn77yM5Y+C5pWwW3ZvdWNoZXJCYXRjaENvZGVd6L2s5YWl5YC8WzE0MDYwMl3mib7kuI3liLDlr7nnhafkv6Hmga8=";
////        byte[] decoded = new BASE64Decoder().decodeBuffer(mm);
//            byte[] decoded = Base64.getMimeDecoder().decode(mm);
//        base64decoderString = new String(decoded,"utf-8");
//        System.out.print(base64decoderString);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        String s ="eyJyYW5kb20iOiIxNTVmOWUiLCJjcmVhdGVUaW1lIjoiMjAyNDA5MjQxNDQ2MTcyMzYiLCJwaWN0dXJlVXJsIjoiaHR0cDovLzE3Mi4xNjguNjkuNjQ6MzAwMDAvc2Fhcy1pbmR1c3RyeS9lYmlsbC5odG1sP3Q9JUM0JUE4XyVDNCVBOCVDNCU4Q0MlQzQlQTRlJUMzJUE1JUMzJUJCZCVDMyU4OCVDNCVBRCVDMyVBOCVDNSU4NSIsInd4Q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RQ2srZWUwSDg0ZFdnQmpXb0lkRkF2VCtWb1BZdTJFc3NGeVlud3BPSEVGejNNTldnQmpXb1llWGo0YVc2TU1TaHh0MUNwdUhyc0Ztb0d0U2dCaldVTklSYjcxd0hhQzU3cERBaG93YlBsWDk2WGcxcVVJTWF6alZzVGlHRWUxNFlaT0IzditXY1hudXYzTFZTZ3hyVW9JYkpXbVF2eUFnbkhxamNERy9kVWVGTGVIYzFxRUVOYWtBMFVBdEI3ZVhVM2ZGMkVaV0JieUs0TnFvR05haEJEYTgxVUtNR2MyVTR2RU1XL2dGUXBVTzhUSm5FVEdwUWd4clVnR3RZcUpGUkRSc3E1d3hqcG5CdVk3cmNxUVkxcUVFTmJ6VE1iYXNMM3hVM0ZHYVAxRE5UcXM3L0pOU2dCaldvNFVRRG5tRlNuUzBxaWFYNldBdnpEWGczcmh3M3FFRU5hbEREMlh4RFdGbWpla0p6My9XVzNoTFZKcVNlVUExcVVJTWExalJRMzVWQ2dPZTNlUEJFbFUxRE9tcFFneHJVc0tZaGJBV0Y2emozOGFnUEUrYko0WUxmbG1HcVFRMXErRklONGYyb3ZKU0tQOElYRE5OajZ0ZXBVbTg1dzFTREd0U2docnYvUDVCZStvZDNidVpPbnN1bHFUUmJEV3BRZ3hvdU5YaDRxTUhqaitNWHBCajNUWkVBZVUwQUFBQUFTVVZPUks1Q1lJST0ifQ==";
        String base64Decoder = getBase64Decoder(s);
        System.out.println(base64Decoder);
    }
}
